<template>
    <div class="noticeRule">
        <div class="noticeRuleDiv" >
            <span class="noticeRuleSpan">{{labelVal[0]}}</span>
            <el-time-select
            v-model="taskTime"
            :picker-options="{
                start: '08:00',
                step: '00:15',
                end: '24:00'
            }"
            placeholder="时:分">
            </el-time-select>
        </div>
        <div class="noticeRuleDiv" >
            <span class="noticeRuleSpan">{{labelVal[1]}}</span>
            <el-time-select
            v-model="overTime"
            size="small"
            :picker-options="{
                start: '08:00',
                step: '00:15',
                end: '24:00'
            }"
            placeholder="时:分">
            </el-time-select>
        </div>
        <div class="noticeRuleDiv" >
            <span class="noticeRuleSpan">{{labelVal[2]}}</span>
             <el-time-picker
                v-model="beforeTime"
                :picker-options="{
                selectableRange: '00:00:00 - 23:59:59'
                }"
                placeholder="时:分:秒">
            </el-time-picker>
        </div>
        <div class="saveHandle">
            <el-button type="primary" @click="saveHandle">保存</el-button>
        </div>
    </div>
</template>

<script>
import { getAdviceRule,postAdviceRule } from '@/api/common/notice/noticerule/index';
import { dictionary } from '@/utils/dictMixin';
export default {
    name:'noticerule',
    mixins: [dictionary],
    data () {
        return {
            taskTime:'08:00',
            overTime:'17:00',
            beforeTime:new Date('', '', '', '', 10),
            labelVal:['任务定时提醒时间设置','逾期任务定时提醒时间设置','即将逾期提醒时间设置'],
            params:{}
        }
    },
    created() {
       this.init() 
    },
    methods: {
        init(){
            let params=['taskTime','overTime','beforeTime']
            getAdviceRule(params).then(res=>{
                console.log(res.data,"res.data[0].paramValue")
                if(res.data[0].paramValue == null){
                    this.taskTime='08:00'
                }
                else if(res.data[1].paramValue == null){
                        this.overTime='17:00'
                    }
                else if(res.data[2].paramValue == null){
                        this.beforeTime= new Date('', '', '', '', 10)
                }else{
                    res.data.forEach(x=>{
                        if(x.paramCode == "taskTime"){
                            this.taskTime=x.paramValue
                        }
                        if(x.paramCode == "overTime"){
                            this.overTime=x.paramValue
                        }
                        if(x.paramCode == "beforeTime"){
                            this.beforeTime=new Date(2016, 9, 10,x.paramValue.split(':')[0],x.paramValue.split(':')[1],x.paramValue.split(':')[2])
                        }

                    })
                    // this.taskTime=res.data[0].paramValue
                    // this.overTime=res.data[1].paramValue
                    //this.beforeTime= new Date(2016, 9, 10,res.data[2].paramValue.split(':')[0],res.data[2].paramValue.split(':')[1],res.data[2].paramValue.split(':')[2])
                }
                // if(res.data.beforeTime == null && res.data.overTime == null && res.data.beforeTime == null){
                //     this.beforeTime='08:00'
                //     this.overTime='17:00'
                //     this.beforeTime= new Date('', '', '', '', 10)
                // }else{
                //     this.beforeTime=res.data.beforeTime
                //     this.overTime=res.data.overTime
                //     this.beforeTime= new Date(2016, 9, 10,res.data.beforeTime.split(':')[0],res.data.beforeTime.split(':')[1],res.data.beforeTime.split(':')[2])
                // }
            })
        },
        //保存
        saveHandle(){
            console.log(this.beforeTime,this.overTime,this.beforeTime,"value0")
            console.log(this.beforeTime.getHours(),this.beforeTime.getMinutes(),this.beforeTime.getSeconds())
            let Hours = this.beforeTime.getHours()<=9?'0'+this.beforeTime.getHours():this.beforeTime.getHours()
            let Minutes = this.beforeTime.getMinutes()<=9?'0'+this.beforeTime.getMinutes():this.beforeTime.getMinutes()
            let Seconds = this.beforeTime.getSeconds()<=9?'0'+this.beforeTime.getSeconds():this.beforeTime.getSeconds()
            let beforeTime=Hours+":"+Minutes+":"+Seconds
            console.log(beforeTime,"beforeTime")
            this.params=[
                  {
                    "paramCode": "taskTime",
                    "paramName": this.labelVal[0],
                    "paramValue": this.taskTime
                },
                  {
                    "paramCode": "overTime",
                    "paramName": this.labelVal[1],
                    "paramValue": this.overTime
                },
                  {
                    "paramCode": "beforeTime",
                    "paramName": this.labelVal[2],
                    "paramValue": beforeTime
                }
            ]
            postAdviceRule(this.params).then(res=>{
                console.log(res,"res")
                if(res.resultCode == 200){
                    this.$message({
                    message: '保存成功',
                    type: 'success'
                    });
                }
            })
        }
    }
}
</script>

<style lang="less">
.noticeRule{
    .noticeRuleDiv{
        margin: 10px 0;
        .noticeRuleSpan{
            display: inline-block;
            margin-right: 20px;
            width: 13%;
        }
    }
    .saveHandle{
        margin:30px 0 10px 11%;
    }
}
</style>
